﻿using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Tookit.Mvvm.Navigation.Message;
using Tookit.Mvvm.Navigation.ViewModels;

namespace Tookit.Mvvm.Navigation.Views
{
    /// <summary>
    /// Shell.xaml 的交互逻辑
    /// </summary>
    public partial class Shell : Window
    {
        public Shell(ShellViewModel shellViewModel)
        {
            InitializeComponent();
            DataContext = shellViewModel;
            // 注册窗口大小消息
            WeakReferenceMessenger.Default.Register<ChangeWindowSizeMessage>(this, (sender, message) => {
                // 先设置窗口大小
                Width = message.Width;
                Height = message.Height;

                // 计算窗口位置使其居中
                Left = (SystemParameters.PrimaryScreenWidth - Width) / 2;
                Top = (SystemParameters.PrimaryScreenHeight - Height) / 2;
            });
        }
    }
}
